import { Entity, PrimaryGeneratedColumn, Column, CreateDateColumn, UpdateDateColumn, ManyToOne, JoinColumn } from 'typeorm';
import { User } from './user.entity';
import { Article } from './article.entity';

@Entity()
export class Comment {
  @PrimaryGeneratedColumn()
  id: number;

  @Column()
  content: string;

  @Column({ nullable: true })
  articleId: number;

  @Column({ nullable: true })
  authorId: number;

  @Column({ type: 'tinyint', default: 1, comment: '状态: 0禁用, 1启用' })
  isActive: number;

  @CreateDateColumn()
  createdAt: Date;

  @UpdateDateColumn()
  updatedAt: Date;

  // 关联关系
  @ManyToOne(() => User, { nullable: true })
  @JoinColumn({ name: 'authorId' })
  author: User;

  @ManyToOne(() => Article, { nullable: true })
  @JoinColumn({ name: 'articleId' })
  article: Article;
}